#pragma once
#pragma pack(1)

#define MSGVERSION '_FYW'
#define BUFFERSIZE 1024*10

///////////////////////////////////////////////////////

#define ios_version
//comment this if you are using in Windows

///////////////////////////////////////////////////////
typedef enum
{
	hNull,
	//hclUserRequestHallAssign,
	//hlcUserGetAssignedHall,
	hchUserLogin,				//用户进入程序 进行登录验证
	hhcUserGetInfo,				//用户登录成功验证 返回当前用户信息
	hchUserRequestRoomSort,		//用户请求房间种类信息
	hhcUserGetSortedRoom,		//用户请求成功 返回房间种类
	hchUserRequestRoomList,		//用户请求一种房间的列表
	hhcUserGetRoomList,			//用户请求成功 返回房间列表
	hchUserRequestRoomInfo,
	hhcUserGetRoomInfo,
	hcgUserRequestGameInfo,
	hgcUserGetGameInfo,
	hMax
} client_server_enum;

///////////////////////////////////////////////////////
typedef struct
{
	char	usrName[33];		//用户登录名
	char	usrPSW[33];			//用户密码
}	UsrAccount,*PUsrAccount;	////用户登录帐户信息
///////////////////////////////////////////////////////
typedef struct
{
	int		usrID;				//用户ID
	UsrAccount usrAcc;			//用户登录帐户信息
	char	usrNick[65];		//用户昵称
	int		usrLevel;			//用户级别
	int	usrCoins;				//用户金币
	long long	usrCounters;	//用户筹码
	char usrInfo[256];			//额外信息json
}	UsrInfo,*PUsrInfo;			//登录验证返回的用户信息
///////////////////////////////////////////////////////
typedef struct
{
	//BOOL---signed char
	int roomId;
	int smallblind;				//小盲
	int ante;					//底注
	int numPeople;				//桌面几个人
	bool isFastSpeed;			//快速
	int numOnTable;				//桌子上有几个人?可选
}	RoomInfo,*PRoomInfo;
typedef struct
{
	char	usrNick[65];		//用户昵称
	int		usrLevel;			//用户级别
	long long	usrCounters;	//用户筹码
	char usrInfo[256];			//用户额外信息json
	int position;				//用户所在桌面的位置
	
}	RoomUsrInfo,*PRoomUsrInfo;	//当前房间用户玩家信息
///////////////////////////////////////////////////////
typedef struct
{
	int smallblind;
//	int numPeople;				//uncomment these
//	bool isFastSpeed;
//	bool isVIPTable;
//	bool isFullTable;
}	RoomSortInfo,*PRoomSortInfo;
///////////////////////////////////////////////////////

/*********************************** for the ios************************* */
#ifdef ios_version
#include <CoreGraphics/CGBase.h>
///////////////////////////////////////////////////////
typedef struct
{
	int msgVer;
	int msgLen;
	int cmdId;
}MessageHeader;
CG_INLINE MessageHeader
NewHeader(int Ver,int Len,int Id)
{
	MessageHeader msg;
	msg.msgVer = Ver;
	msg.msgLen = Len;
	msg.cmdId = Id;
	return msg;
}
///////////////////////////////////////////////////////
CG_INLINE UsrAccount
NewAccount(NSData *userName,NSData *userPSW)
{
	UsrAccount ua;
	size_t userNameLen = [userName length]> sizeof(ua.usrName) -1?sizeof(ua.usrName) -1:[userName length];
	size_t userPSWLen = [userPSW length]> sizeof(ua.usrPSW) -1?sizeof(ua.usrPSW) -1:[userPSW length];
		
	memcpy(ua.usrName,[userName bytes],userNameLen);
	ua.usrName[userNameLen] = 0;
	
	memcpy(ua.usrPSW,[userPSW bytes],userPSWLen);
	ua.usrPSW[userPSWLen] = 0;
	
	//show result

	printf("usrName:%s\n",ua.usrName);
	printf("usrPSW:%s\n",ua.usrPSW);
	
	return ua;
}
///////////////////////////////////////////////////////
CG_INLINE UsrInfo
NewUsrInfo(PUsrInfo uip)
{
	UsrInfo ui;
//	memset(&ui,0,sizeof(UsrInfo));
//	for (int i =0;  i<65; i++) {
//		printf("i:%d,%d\n",i,ui.usrNick[i]);
//	}
	memcpy(&ui,uip,sizeof(UsrInfo));
	
//	for (int i =0;  i<65; i++) {
//		printf("i:%d,%d\n",i,ui.usrNick[i]);
//	}
	
	return ui;
}
CG_INLINE int
SizeofUnichar(unichar * source)
{
	int i=0;
	for (; *(source+i); i++) {	
	}
	return i;
}
///////////////////////////////////////////////////////
typedef struct
{
	RoomSortInfo * sortedRoom;
	int num;

}	RoomSort,*PRoomSort;// for the client and not for the server
CG_INLINE RoomSort
NewRoomSort (RoomSortInfo * sorted,int num)
{
	RoomSort rs;
	rs.sortedRoom = sorted;
	rs.num = num;
	return rs;
}
///////////////////////////////////////////////////////

CG_INLINE RoomInfo
NewRoomInfo(PRoomInfo rip)
{
	RoomInfo ri;
	memcpy(&ri,rip,sizeof(RoomInfo));
	return ri;
}
///////////////////////////////////////////////////////
typedef struct
{
	RoomInfo * room;
	int num;
}	RoomList,PRoomList;
CG_INLINE RoomList
NewRoomList(PRoomInfo ri,int num)
{
	RoomList rl;
	rl.room = ri;
	rl.num = num;
	return rl;
}
CG_INLINE RoomList
NewRoomListNon()
{
	RoomList rl;
	rl.room = NULL;
	rl.num = 0;
	return rl;
}
///////////////////////////////////////////////////////


#endif
